home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample PMSAM / PMSAM Framework / RoboSamSlot / LogErrors.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  2.8 KB  |  130 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        LogError.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Tim Harnett
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>     2/21/95    TMH        metrowerks compatiblity changes
  13.          <3>      2/9/95    TMH        added LimitErrorReport flag
  14.          <2>     10/7/94    TMH        added maxReport limiting
  15.          <1>     10/6/94    TMH        seperated from TMSAMSlot
  16.                  10/4/94    TMH        xxx put comment here xxx
  17.  
  18.     To Do:
  19. */
  20.  
  21.  
  22. #ifndef __RESOURCES__
  23. #include "Resources.h"
  24. #endif
  25.  
  26.  
  27. #ifndef __LogErrors__
  28. #include "LogErrors.h"
  29. #endif
  30.  
  31. #ifndef __MSAMSlot__
  32. #include "MSAMSlot.h"
  33. #endif
  34.  
  35. Boolean gLimitErrorReports = false;    // set from resource
  36.  
  37.  
  38.  
  39. //------------------------------------------------------------------------------------------
  40. Boolean GetLogEntry(short osErr,MailErrorLogEntryInfo& logEntry);  // the compiler insists
  41. Boolean GetLogEntry(short osErr,MailErrorLogEntryInfo& logEntry)
  42. {
  43.         //    We get the table into memory and we want it kept there. 
  44.         
  45.     static LogMessageTableEntry** pTable = 0;
  46.     if( pTable == 0 ) {
  47.         pTable = (LogMessageTableEntry**)GetResource('etbl', kLogErrorMapTable);
  48.         DetachResource((Handle)pTable);
  49.         HNoPurge((Handle)pTable);
  50.     }
  51.  
  52.  
  53.         //    Set defaults -- arbitrary
  54.     logEntry.errorResource = 1;
  55.     logEntry.actionResource = 1;
  56.     logEntry.errorType = kMailELEWarning;
  57.     logEntry.errorCode = kMailMSAMErrorCode;
  58.  
  59.     if (pTable) {
  60.  
  61.         LogMessageTableEntry* pEntry = *pTable;        // Caution! dereferenced handle.
  62.  
  63.         short lenTab = (short)(GetHandleSize((Handle)pTable) / sizeof(LogMessageTableEntry));
  64.         for (short i = 1; i <= lenTab; ++i, ++pEntry) {
  65.         
  66.             if ( (pEntry->lowErr <= osErr) && (osErr <= pEntry->highErr))  {        // is error in error range.
  67.  
  68.                 if( (pEntry->reportCount < pEntry->maxReports) || !gLimitErrorReports ) {
  69.                 
  70.                     logEntry.errorResource = pEntry->errorIndex;
  71.                     logEntry.actionResource = pEntry->actionIndex;
  72.                     logEntry.errorType = pEntry->errorType;
  73.                     logEntry.errorCode = pEntry->errorCode;
  74.                 
  75.                     pEntry->reportCount++;
  76.  
  77.                     return true;
  78.  
  79.                 }
  80.                 
  81.             }
  82.         }
  83.  
  84.     }
  85.     
  86.     return false;
  87.  
  88.  
  89. //-----------------------------------------------------------------------------
  90. void LogError(OSErr osErr,TMSAMSlot* slot)
  91. {
  92.  
  93.     if(osErr == errAlreadyLogged)
  94.         return;
  95.         
  96.     //    slot == 0 means its a MSAM level error
  97.     
  98.     MailErrorLogEntryInfo    logEntry;
  99.     PMSAMLogErrorPB pb;
  100.     
  101.     
  102.     //    Map the error # to the string & action index
  103.     
  104.  
  105.     logEntry.version = kMailErrorLogEntryVersion;
  106.  
  107.     if( GetLogEntry(osErr,logEntry) ) {
  108.         
  109.         pb.logEntry = &logEntry;
  110.         pb.msamSlotID = 0;
  111.         if( slot != 0 )
  112.             pb.msamSlotID = slot->GetSlotID();
  113.         
  114.         OSErr osErr = PMSAMLogError((MSAMParam *)&pb);
  115.     }
  116.     
  117.     
  118. #ifdef JUNK
  119.     // Do we do something like this?
  120.     if( logEntry.errorCode == kMailELECorrectable )
  121.         if( slot == 0 )
  122.             gApplication->SuspendPMSAM();
  123.         else
  124.             slot->Suspend();
  125. #endif
  126.  
  127.     
  128. }
  129.